home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / include / d3dx8math.h < prev    next >
C/C++ Source or Header  |  2001-10-08  |  39KB  |  1,216 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (C) Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //  File:       d3dx8math.h
  6. //  Content:    D3DX math types and functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "d3dx8.h"
  11.  
  12. #ifndef __D3DX8MATH_H__
  13. #define __D3DX8MATH_H__
  14.  
  15. #include <math.h>
  16. #pragma warning(disable:4201) // anonymous unions warning
  17.  
  18.  
  19.  
  20. //===========================================================================
  21. //
  22. // General purpose utilities
  23. //
  24. //===========================================================================
  25. #define D3DX_PI    ((FLOAT)  3.141592654f)
  26. #define D3DX_1BYPI ((FLOAT)  0.318309886f)
  27.  
  28. #define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f))
  29. #define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI))
  30.  
  31.  
  32.  
  33. //===========================================================================
  34. //
  35. // Vectors
  36. //
  37. //===========================================================================
  38.  
  39. //--------------------------
  40. // 2D Vector
  41. //--------------------------
  42. typedef struct D3DXVECTOR2
  43. {
  44. #ifdef __cplusplus
  45. public:
  46.     D3DXVECTOR2() {};
  47.     D3DXVECTOR2( CONST FLOAT * );
  48.     D3DXVECTOR2( FLOAT x, FLOAT y );
  49.  
  50.     // casting
  51.     operator FLOAT* ();
  52.     operator CONST FLOAT* () const;
  53.  
  54.     // assignment operators
  55.     D3DXVECTOR2& operator += ( CONST D3DXVECTOR2& );
  56.     D3DXVECTOR2& operator -= ( CONST D3DXVECTOR2& );
  57.     D3DXVECTOR2& operator *= ( FLOAT );
  58.     D3DXVECTOR2& operator /= ( FLOAT );
  59.  
  60.     // unary operators
  61.     D3DXVECTOR2 operator + () const;
  62.     D3DXVECTOR2 operator - () const;
  63.  
  64.     // binary operators
  65.     D3DXVECTOR2 operator + ( CONST D3DXVECTOR2& ) const;
  66.     D3DXVECTOR2 operator - ( CONST D3DXVECTOR2& ) const;
  67.     D3DXVECTOR2 operator * ( FLOAT ) const;
  68.     D3DXVECTOR2 operator / ( FLOAT ) const;
  69.  
  70.     friend D3DXVECTOR2 operator * ( FLOAT, CONST D3DXVECTOR2& );
  71.  
  72.     BOOL operator == ( CONST D3DXVECTOR2& ) const;
  73.     BOOL operator != ( CONST D3DXVECTOR2& ) const;
  74.  
  75.  
  76. public:
  77. #endif //__cplusplus
  78.     FLOAT x, y;
  79. } D3DXVECTOR2, *LPD3DXVECTOR2;
  80.  
  81.  
  82. //--------------------------
  83. // 3D Vector
  84. //--------------------------
  85. #ifdef __cplusplus
  86. typedef struct D3DXVECTOR3 : public D3DVECTOR
  87. {
  88. public:
  89.     D3DXVECTOR3() {};
  90.     D3DXVECTOR3( CONST FLOAT * );
  91.     D3DXVECTOR3( CONST D3DVECTOR& );
  92.     D3DXVECTOR3( FLOAT x, FLOAT y, FLOAT z );
  93.  
  94.     // casting
  95.     operator FLOAT* ();
  96.     operator CONST FLOAT* () const;
  97.  
  98.     // assignment operators
  99.     D3DXVECTOR3& operator += ( CONST D3DXVECTOR3& );
  100.     D3DXVECTOR3& operator -= ( CONST D3DXVECTOR3& );
  101.     D3DXVECTOR3& operator *= ( FLOAT );
  102.     D3DXVECTOR3& operator /= ( FLOAT );
  103.  
  104.     // unary operators
  105.     D3DXVECTOR3 operator + () const;
  106.     D3DXVECTOR3 operator - () const;
  107.  
  108.     // binary operators
  109.     D3DXVECTOR3 operator + ( CONST D3DXVECTOR3& ) const;
  110.     D3DXVECTOR3 operator - ( CONST D3DXVECTOR3& ) const;
  111.     D3DXVECTOR3 operator * ( FLOAT ) const;
  112.     D3DXVECTOR3 operator / ( FLOAT ) const;
  113.  
  114.     friend D3DXVECTOR3 operator * ( FLOAT, CONST struct D3DXVECTOR3& );
  115.  
  116.     BOOL operator == ( CONST D3DXVECTOR3& ) const;
  117.     BOOL operator != ( CONST D3DXVECTOR3& ) const;
  118.  
  119. } D3DXVECTOR3, *LPD3DXVECTOR3;
  120.  
  121. #else //!__cplusplus
  122. typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3;
  123. #endif //!__cplusplus
  124.  
  125.  
  126. //--------------------------
  127. // 4D Vector
  128. //--------------------------
  129. typedef struct D3DXVECTOR4
  130. {
  131. #ifdef __cplusplus
  132. public:
  133.     D3DXVECTOR4() {};
  134.     D3DXVECTOR4( CONST FLOAT* );
  135.     D3DXVECTOR4( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
  136.  
  137.     // casting
  138.     operator FLOAT* ();
  139.     operator CONST FLOAT* () const;
  140.  
  141.     // assignment operators
  142.     D3DXVECTOR4& operator += ( CONST D3DXVECTOR4& );
  143.     D3DXVECTOR4& operator -= ( CONST D3DXVECTOR4& );
  144.     D3DXVECTOR4& operator *= ( FLOAT );
  145.     D3DXVECTOR4& operator /= ( FLOAT );
  146.  
  147.     // unary operators
  148.     D3DXVECTOR4 operator + () const;
  149.     D3DXVECTOR4 operator - () const;
  150.  
  151.     // binary operators
  152.     D3DXVECTOR4 operator + ( CONST D3DXVECTOR4& ) const;
  153.     D3DXVECTOR4 operator - ( CONST D3DXVECTOR4& ) const;
  154.     D3DXVECTOR4 operator * ( FLOAT ) const;
  155.     D3DXVECTOR4 operator / ( FLOAT ) const;
  156.  
  157.     friend D3DXVECTOR4 operator * ( FLOAT, CONST D3DXVECTOR4& );
  158.  
  159.     BOOL operator == ( CONST D3DXVECTOR4& ) const;
  160.     BOOL operator != ( CONST D3DXVECTOR4& ) const;
  161.  
  162. public:
  163. #endif //__cplusplus
  164.     FLOAT x, y, z, w;
  165. } D3DXVECTOR4, *LPD3DXVECTOR4;
  166.  
  167.  
  168. //===========================================================================
  169. //
  170. // Matrices
  171. //
  172. //===========================================================================
  173. #ifdef __cplusplus
  174. typedef struct D3DXMATRIX : public D3DMATRIX
  175. {
  176. public:
  177.     D3DXMATRIX() {};
  178.     D3DXMATRIX( CONST FLOAT * );
  179.     D3DXMATRIX( CONST D3DMATRIX& );
  180.     D3DXMATRIX( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
  181.                 FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
  182.                 FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
  183.                 FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
  184.  
  185.  
  186.     // access grants
  187.     FLOAT& operator () ( UINT Row, UINT Col );
  188.     FLOAT  operator () ( UINT Row, UINT Col ) const;
  189.  
  190.     // casting operators
  191.     operator FLOAT* ();
  192.     operator CONST FLOAT* () const;
  193.  
  194.     // assignment operators
  195.     D3DXMATRIX& operator *= ( CONST D3DXMATRIX& );
  196.     D3DXMATRIX& operator += ( CONST D3DXMATRIX& );
  197.     D3DXMATRIX& operator -= ( CONST D3DXMATRIX& );
  198.     D3DXMATRIX& operator *= ( FLOAT );
  199.     D3DXMATRIX& operator /= ( FLOAT );
  200.  
  201.     // unary operators
  202.     D3DXMATRIX operator + () const;
  203.     D3DXMATRIX operator - () const;
  204.  
  205.     // binary operators
  206.     D3DXMATRIX operator * ( CONST D3DXMATRIX& ) const;
  207.     D3DXMATRIX operator + ( CONST D3DXMATRIX& ) const;
  208.     D3DXMATRIX operator - ( CONST D3DXMATRIX& ) const;
  209.     D3DXMATRIX operator * ( FLOAT ) const;
  210.     D3DXMATRIX operator / ( FLOAT ) const;
  211.  
  212.     friend D3DXMATRIX operator * ( FLOAT, CONST D3DXMATRIX& );
  213.  
  214.     BOOL operator == ( CONST D3DXMATRIX& ) const;
  215.     BOOL operator != ( CONST D3DXMATRIX& ) const;
  216.  
  217. } D3DXMATRIX, *LPD3DXMATRIX;
  218.  
  219. #else //!__cplusplus
  220. typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
  221. #endif //!__cplusplus
  222.  
  223. //===========================================================================
  224. //
  225. // Aligned Matrices
  226. //
  227. // This class helps keep matrices 16-byte aligned as preferred by P4 cpus.
  228. // It aligns matrices on the stack and on the heap or in global scope.
  229. // It does this using __declspec(align(16)) which works on VC7 and on VC 6
  230. // with the processor pack. Unfortunately there is no way to detect the 
  231. // latter so this is turned on only on VC7. On other compilers this is the
  232. // the same as D3DXMATRIX.
  233. // Using this class on a compiler that does not actually do the alignment
  234. // can be dangerous since it will not expose bugs that ignore alignment.
  235. // E.g if an object of this class in inside a struct or class, and some code
  236. // memcopys data in it assuming tight packing. This could break on a compiler
  237. // that eventually start aligning the matrix.
  238. //
  239. //===========================================================================
  240. #ifdef __cplusplus
  241. typedef struct _D3DXMATRIXA16 : public D3DXMATRIX
  242. {
  243.     _D3DXMATRIXA16() {}
  244.     _D3DXMATRIXA16( CONST FLOAT * f): D3DXMATRIX(f) {}
  245.     _D3DXMATRIXA16( CONST D3DMATRIX& m): D3DXMATRIX(m) {}
  246.     _D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
  247.                     FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
  248.                     FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
  249.                     FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 ) :
  250.                 D3DXMATRIX(_11, _12, _13, _14,
  251.                            _21, _22, _23, _24,
  252.                            _31, _32, _33, _34,
  253.                            _41, _42, _43, _44) {}
  254.     void* operator new(size_t s)
  255.     {
  256.         LPBYTE p = ::new BYTE[s + 16];
  257.         if (p)
  258.         {
  259.             BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15));
  260.             p += offset;
  261.             p[-1] = offset;
  262.         }
  263.         return p;
  264.     };
  265.  
  266.     void* operator new[](size_t s)
  267.     {
  268.         LPBYTE p = ::new BYTE[s + 16];
  269.         if (p)
  270.         {
  271.             BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15));
  272.             p += offset;
  273.             p[-1] = offset;
  274.         }
  275.         return p;
  276.     };
  277.  
  278.     // This is NOT a virtual operator. If you cast
  279.     // to D3DXMATRIX, do not delete using that
  280.     void operator delete(void* p)
  281.     {
  282.         if(p)
  283.         {
  284.             BYTE* pb = static_cast<BYTE*>(p);
  285.             pb -= pb[-1];
  286.             ::delete [] pb;
  287.         }
  288.     };
  289.  
  290.     // This is NOT a virtual operator. If you cast
  291.     // to D3DXMATRIX, do not delete using that
  292.     void operator delete[](void* p)
  293.     {
  294.         if(p)
  295.         {
  296.             BYTE* pb = static_cast<BYTE*>(p);
  297.             pb -= pb[-1];
  298.             ::delete [] pb;
  299.         }
  300.     };
  301.  
  302.     struct _D3DXMATRIXA16& operator=(CONST D3DXMATRIX& rhs)
  303.     {
  304.         memcpy(&_11, &rhs, sizeof(D3DXMATRIX));
  305.         return *this;
  306.     };
  307. } _D3DXMATRIXA16;
  308.  
  309. #else //!__cplusplus
  310. typedef D3DXMATRIX  _D3DXMATRIXA16;
  311. #endif //!__cplusplus
  312.  
  313. #if _MSC_VER >= 1300        // VC7
  314. #define _ALIGN_16 __declspec(align(16))
  315. #else
  316. #define _ALIGN_16                   // Earlier compiler may not understand this, do nothing.
  317. #endif
  318.  
  319. #define D3DXMATRIXA16 _ALIGN_16 _D3DXMATRIXA16
  320.  
  321. typedef D3DXMATRIXA16 *LPD3DXMATRIXA16;
  322.  
  323. //===========================================================================
  324. //
  325. //    Quaternions
  326. //
  327. //===========================================================================
  328. typedef struct D3DXQUATERNION
  329. {
  330. #ifdef __cplusplus
  331. public:
  332.     D3DXQUATERNION() {}
  333.     D3DXQUATERNION( CONST FLOAT * );
  334.     D3DXQUATERNION( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
  335.  
  336.     // casting
  337.     operator FLOAT* ();
  338.     operator CONST FLOAT* () const;
  339.  
  340.     // assignment operators
  341.     D3DXQUATERNION& operator += ( CONST D3DXQUATERNION& );
  342.     D3DXQUATERNION& operator -= ( CONST D3DXQUATERNION& );
  343.     D3DXQUATERNION& operator *= ( CONST D3DXQUATERNION& );
  344.     D3DXQUATERNION& operator *= ( FLOAT );
  345.     D3DXQUATERNION& operator /= ( FLOAT );
  346.  
  347.     // unary operators
  348.     D3DXQUATERNION  operator + () const;
  349.     D3DXQUATERNION  operator - () const;
  350.  
  351.     // binary operators
  352.     D3DXQUATERNION operator + ( CONST D3DXQUATERNION& ) const;
  353.     D3DXQUATERNION operator - ( CONST D3DXQUATERNION& ) const;
  354.     D3DXQUATERNION operator * ( CONST D3DXQUATERNION& ) const;
  355.     D3DXQUATERNION operator * ( FLOAT ) const;
  356.     D3DXQUATERNION operator / ( FLOAT ) const;
  357.  
  358.     friend D3DXQUATERNION operator * (FLOAT, CONST D3DXQUATERNION& );
  359.  
  360.     BOOL operator == ( CONST D3DXQUATERNION& ) const;
  361.     BOOL operator != ( CONST D3DXQUATERNION& ) const;
  362.  
  363. #endif //__cplusplus
  364.     FLOAT x, y, z, w;
  365. } D3DXQUATERNION, *LPD3DXQUATERNION;
  366.  
  367.  
  368. //===========================================================================
  369. //
  370. // Planes
  371. //
  372. //===========================================================================
  373. typedef struct D3DXPLANE
  374. {
  375. #ifdef __cplusplus
  376. public:
  377.     D3DXPLANE() {}
  378.     D3DXPLANE( CONST FLOAT* );
  379.     D3DXPLANE( FLOAT a, FLOAT b, FLOAT c, FLOAT d );
  380.  
  381.     // casting
  382.     operator FLOAT* ();
  383.     operator CONST FLOAT* () const;
  384.  
  385.     // unary operators
  386.     D3DXPLANE operator + () const;
  387.     D3DXPLANE operator - () const;
  388.  
  389.     // binary operators
  390.     BOOL operator == ( CONST D3DXPLANE& ) const;
  391.     BOOL operator != ( CONST D3DXPLANE& ) const;
  392.  
  393. #endif //__cplusplus
  394.     FLOAT a, b, c, d;
  395. } D3DXPLANE, *LPD3DXPLANE;
  396.  
  397.  
  398. //===========================================================================
  399. //
  400. // Colors
  401. //
  402. //===========================================================================
  403.  
  404. typedef struct D3DXCOLOR
  405. {
  406. #ifdef __cplusplus
  407. public:
  408.     D3DXCOLOR() {}
  409.     D3DXCOLOR( DWORD argb );
  410.     D3DXCOLOR( CONST FLOAT * );
  411.     D3DXCOLOR( CONST D3DCOLORVALUE& );
  412.     D3DXCOLOR( FLOAT r, FLOAT g, FLOAT b, FLOAT a );
  413.  
  414.     // casting
  415.     operator DWORD () const;
  416.  
  417.     operator FLOAT* ();
  418.     operator CONST FLOAT* () const;
  419.  
  420.     operator D3DCOLORVALUE* ();
  421.     operator CONST D3DCOLORVALUE* () const;
  422.  
  423.     operator D3DCOLORVALUE& ();
  424.     operator CONST D3DCOLORVALUE& () const;
  425.  
  426.     // assignment operators
  427.     D3DXCOLOR& operator += ( CONST D3DXCOLOR& );
  428.     D3DXCOLOR& operator -= ( CONST D3DXCOLOR& );
  429.     D3DXCOLOR& operator *= ( FLOAT );
  430.     D3DXCOLOR& operator /= ( FLOAT );
  431.  
  432.     // unary operators
  433.     D3DXCOLOR operator + () const;
  434.     D3DXCOLOR operator - () const;
  435.  
  436.     // binary operators
  437.     D3DXCOLOR operator + ( CONST D3DXCOLOR& ) const;
  438.     D3DXCOLOR operator - ( CONST D3DXCOLOR& ) const;
  439.     D3DXCOLOR operator * ( FLOAT ) const;
  440.     D3DXCOLOR operator / ( FLOAT ) const;
  441.  
  442.     friend D3DXCOLOR operator * (FLOAT, CONST D3DXCOLOR& );
  443.  
  444.     BOOL operator == ( CONST D3DXCOLOR& ) const;
  445.     BOOL operator != ( CONST D3DXCOLOR& ) const;
  446.  
  447. #endif //__cplusplus
  448.     FLOAT r, g, b, a;
  449. } D3DXCOLOR, *LPD3DXCOLOR;
  450.  
  451.  
  452.  
  453. //===========================================================================
  454. //
  455. // D3DX math functions:
  456. //
  457. // NOTE:
  458. //  * All these functions can take the same object as in and out parameters.
  459. //
  460. //  * Out parameters are typically also returned as return values, so that
  461. //    the output of one function may be used as a parameter to another.
  462. //
  463. //===========================================================================
  464.  
  465. //--------------------------
  466. // 2D Vector
  467. //--------------------------
  468.  
  469. // inline
  470.  
  471. FLOAT D3DXVec2Length
  472.     ( CONST D3DXVECTOR2 *pV );
  473.  
  474. FLOAT D3DXVec2LengthSq
  475.     ( CONST D3DXVECTOR2 *pV );
  476.  
  477. FLOAT D3DXVec2Dot
  478.     ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  479.  
  480. // Z component of ((x1,y1,0) cross (x2,y2,0))
  481. FLOAT D3DXVec2CCW
  482.     ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  483.  
  484. D3DXVECTOR2* D3DXVec2Add
  485.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  486.  
  487. D3DXVECTOR2* D3DXVec2Subtract
  488.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  489.  
  490. // Minimize each component.  x = min(x1, x2), y = min(y1, y2)
  491. D3DXVECTOR2* D3DXVec2Minimize
  492.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  493.  
  494. // Maximize each component.  x = max(x1, x2), y = max(y1, y2)
  495. D3DXVECTOR2* D3DXVec2Maximize
  496.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  497.  
  498. D3DXVECTOR2* D3DXVec2Scale
  499.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, FLOAT s );
  500.  
  501. // Linear interpolation. V1 + s(V2-V1)
  502. D3DXVECTOR2* D3DXVec2Lerp
  503.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
  504.       FLOAT s );
  505.  
  506. // non-inline
  507. #ifdef __cplusplus
  508. extern "C" {
  509. #endif
  510.  
  511. D3DXVECTOR2* WINAPI D3DXVec2Normalize
  512.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV );
  513.  
  514. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  515. // and position V2, tangent T2 (when s == 1).
  516. D3DXVECTOR2* WINAPI D3DXVec2Hermite
  517.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pT1,
  518.       CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pT2, FLOAT s );
  519.  
  520. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  521. D3DXVECTOR2* WINAPI D3DXVec2CatmullRom
  522.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV0, CONST D3DXVECTOR2 *pV1,
  523.       CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pV3, FLOAT s );
  524.  
  525. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  526. D3DXVECTOR2* WINAPI D3DXVec2BaryCentric
  527.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
  528.       CONST D3DXVECTOR2 *pV3, FLOAT f, FLOAT g);
  529.  
  530. // Transform (x, y, 0, 1) by matrix.
  531. D3DXVECTOR4* WINAPI D3DXVec2Transform
  532.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  533.  
  534. // Transform (x, y, 0, 1) by matrix, project result back into w=1.
  535. D3DXVECTOR2* WINAPI D3DXVec2TransformCoord
  536.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  537.  
  538. // Transform (x, y, 0, 0) by matrix.
  539. D3DXVECTOR2* WINAPI D3DXVec2TransformNormal
  540.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  541.  
  542. #ifdef __cplusplus
  543. }
  544. #endif
  545.  
  546.  
  547. //--------------------------
  548. // 3D Vector
  549. //--------------------------
  550.  
  551. // inline
  552.  
  553. FLOAT D3DXVec3Length
  554.     ( CONST D3DXVECTOR3 *pV );
  555.  
  556. FLOAT D3DXVec3LengthSq
  557.     ( CONST D3DXVECTOR3 *pV );
  558.  
  559. FLOAT D3DXVec3Dot
  560.     ( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  561.  
  562. D3DXVECTOR3* D3DXVec3Cross
  563.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  564.  
  565. D3DXVECTOR3* D3DXVec3Add
  566.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  567.  
  568. D3DXVECTOR3* D3DXVec3Subtract
  569.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  570.  
  571. // Minimize each component.  x = min(x1, x2), y = min(y1, y2), ...
  572. D3DXVECTOR3* D3DXVec3Minimize
  573.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  574.  
  575. // Maximize each component.  x = max(x1, x2), y = max(y1, y2), ...
  576. D3DXVECTOR3* D3DXVec3Maximize
  577.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  578.  
  579. D3DXVECTOR3* D3DXVec3Scale
  580.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s);
  581.  
  582. // Linear interpolation. V1 + s(V2-V1)
  583. D3DXVECTOR3* D3DXVec3Lerp
  584.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  585.       FLOAT s );
  586.  
  587. // non-inline
  588. #ifdef __cplusplus
  589. extern "C" {
  590. #endif
  591.  
  592. D3DXVECTOR3* WINAPI D3DXVec3Normalize
  593.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV );
  594.  
  595. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  596. // and position V2, tangent T2 (when s == 1).
  597. D3DXVECTOR3* WINAPI D3DXVec3Hermite
  598.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pT1,
  599.       CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pT2, FLOAT s );
  600.  
  601. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  602. D3DXVECTOR3* WINAPI D3DXVec3CatmullRom
  603.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV0, CONST D3DXVECTOR3 *pV1,
  604.       CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pV3, FLOAT s );
  605.  
  606. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  607. D3DXVECTOR3* WINAPI D3DXVec3BaryCentric
  608.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  609.       CONST D3DXVECTOR3 *pV3, FLOAT f, FLOAT g);
  610.  
  611. // Transform (x, y, z, 1) by matrix.
  612. D3DXVECTOR4* WINAPI D3DXVec3Transform
  613.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  614.  
  615. // Transform (x, y, z, 1) by matrix, project result back into w=1.
  616. D3DXVECTOR3* WINAPI D3DXVec3TransformCoord
  617.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  618.  
  619. // Transform (x, y, z, 0) by matrix.  If you transforming a normal by a 
  620. // non-affine matrix, the matrix you pass to this function should be the 
  621. // transpose of the inverse of the matrix you would use to transform a coord.
  622. D3DXVECTOR3* WINAPI D3DXVec3TransformNormal
  623.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  624.  
  625. // Project vector from object space into screen space
  626. D3DXVECTOR3* WINAPI D3DXVec3Project
  627.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DVIEWPORT8 *pViewport,
  628.       CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
  629.  
  630. // Project vector from screen space into object space
  631. D3DXVECTOR3* WINAPI D3DXVec3Unproject
  632.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DVIEWPORT8 *pViewport,
  633.       CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
  634.  
  635. #ifdef __cplusplus
  636. }
  637. #endif
  638.  
  639.  
  640.  
  641. //--------------------------
  642. // 4D Vector
  643. //--------------------------
  644.  
  645. // inline
  646.  
  647. FLOAT D3DXVec4Length
  648.     ( CONST D3DXVECTOR4 *pV );
  649.  
  650. FLOAT D3DXVec4LengthSq
  651.     ( CONST D3DXVECTOR4 *pV );
  652.  
  653. FLOAT D3DXVec4Dot
  654.     ( CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2 );
  655.  
  656. D3DXVECTOR4* D3DXVec4Add
  657.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  658.  
  659. D3DXVECTOR4* D3DXVec4Subtract
  660.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  661.  
  662. // Minimize each component.  x = min(x1, x2), y = min(y1, y2), ...
  663. D3DXVECTOR4* D3DXVec4Minimize
  664.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  665.  
  666. // Maximize each component.  x = max(x1, x2), y = max(y1, y2), ...
  667. D3DXVECTOR4* D3DXVec4Maximize
  668.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  669.  
  670. D3DXVECTOR4* D3DXVec4Scale
  671.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, FLOAT s);
  672.  
  673. // Linear interpolation. V1 + s(V2-V1)
  674. D3DXVECTOR4* D3DXVec4Lerp
  675.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  676.       FLOAT s );
  677.  
  678. // non-inline
  679. #ifdef __cplusplus
  680. extern "C" {
  681. #endif
  682.  
  683. // Cross-product in 4 dimensions.
  684. D3DXVECTOR4* WINAPI D3DXVec4Cross
  685.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  686.       CONST D3DXVECTOR4 *pV3);
  687.  
  688. D3DXVECTOR4* WINAPI D3DXVec4Normalize
  689.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV );
  690.  
  691. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  692. // and position V2, tangent T2 (when s == 1).
  693. D3DXVECTOR4* WINAPI D3DXVec4Hermite
  694.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pT1,
  695.       CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pT2, FLOAT s );
  696.  
  697. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  698. D3DXVECTOR4* WINAPI D3DXVec4CatmullRom
  699.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV0, CONST D3DXVECTOR4 *pV1,
  700.       CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pV3, FLOAT s );
  701.  
  702. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  703. D3DXVECTOR4* WINAPI D3DXVec4BaryCentric
  704.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  705.       CONST D3DXVECTOR4 *pV3, FLOAT f, FLOAT g);
  706.  
  707. // Transform vector by matrix.
  708. D3DXVECTOR4* WINAPI D3DXVec4Transform
  709.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM );
  710.  
  711. #ifdef __cplusplus
  712. }
  713. #endif
  714.  
  715.  
  716. //--------------------------
  717. // 4D Matrix
  718. //--------------------------
  719.  
  720. // inline
  721.  
  722. D3DXMATRIX* D3DXMatrixIdentity
  723.     ( D3DXMATRIX *pOut );
  724.  
  725. BOOL D3DXMatrixIsIdentity
  726.     ( CONST D3DXMATRIX *pM );
  727.  
  728.  
  729. // non-inline
  730. #ifdef __cplusplus
  731. extern "C" {
  732. #endif
  733.  
  734. FLOAT WINAPI D3DXMatrixfDeterminant
  735.     ( CONST D3DXMATRIX *pM );
  736.  
  737. D3DXMATRIX* WINAPI D3DXMatrixTranspose
  738.     ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM );
  739.  
  740. // Matrix multiplication.  The result represents the transformation M2
  741. // followed by the transformation M1.  (Out = M1 * M2)
  742. D3DXMATRIX* WINAPI D3DXMatrixMultiply
  743.     ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  744.  
  745. // Matrix multiplication, followed by a transpose. (Out = T(M1 * M2))
  746. D3DXMATRIX* WINAPI D3DXMatrixMultiplyTranspose
  747.     ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  748.  
  749. // Calculate inverse of matrix.  Inversion my fail, in which case NULL will
  750. // be returned.  The determinant of pM is also returned it pfDeterminant
  751. // is non-NULL.
  752. D3DXMATRIX* WINAPI D3DXMatrixInverse
  753.     ( D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM );
  754.  
  755. // Build a matrix which scales by (sx, sy, sz)
  756. D3DXMATRIX* WINAPI D3DXMatrixScaling
  757.     ( D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz );
  758.  
  759. // Build a matrix which translates by (x, y, z)
  760. D3DXMATRIX* WINAPI D3DXMatrixTranslation
  761.     ( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
  762.  
  763. // Build a matrix which rotates around the X axis
  764. D3DXMATRIX* WINAPI D3DXMatrixRotationX
  765.     ( D3DXMATRIX *pOut, FLOAT Angle );
  766.  
  767. // Build a matrix which rotates around the Y axis
  768. D3DXMATRIX* WINAPI D3DXMatrixRotationY
  769.     ( D3DXMATRIX *pOut, FLOAT Angle );
  770.  
  771. // Build a matrix which rotates around the Z axis
  772. D3DXMATRIX* WINAPI D3DXMatrixRotationZ
  773.     ( D3DXMATRIX *pOut, FLOAT Angle );
  774.  
  775. // Build a matrix which rotates around an arbitrary axis
  776. D3DXMATRIX* WINAPI D3DXMatrixRotationAxis
  777.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
  778.  
  779. // Build a matrix from a quaternion
  780. D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion
  781.     ( D3DXMATRIX *pOut, CONST D3DXQUATERNION *pQ);
  782.  
  783. // Yaw around the Y axis, a pitch around the X axis,
  784. // and a roll around the Z axis.
  785. D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll
  786.     ( D3DXMATRIX *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
  787.  
  788.  
  789. // Build transformation matrix.  NULL arguments are treated as identity.
  790. // Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
  791. D3DXMATRIX* WINAPI D3DXMatrixTransformation
  792.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pScalingCenter,
  793.       CONST D3DXQUATERNION *pScalingRotation, CONST D3DXVECTOR3 *pScaling,
  794.       CONST D3DXVECTOR3 *pRotationCenter, CONST D3DXQUATERNION *pRotation,
  795.       CONST D3DXVECTOR3 *pTranslation);
  796.  
  797. // Build affine transformation matrix.  NULL arguments are treated as identity.
  798. // Mout = Ms * Mrc-1 * Mr * Mrc * Mt
  799. D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation
  800.     ( D3DXMATRIX *pOut, FLOAT Scaling, CONST D3DXVECTOR3 *pRotationCenter,
  801.       CONST D3DXQUATERNION *pRotation, CONST D3DXVECTOR3 *pTranslation);
  802.  
  803. // Build a lookat matrix. (right-handed)
  804. D3DXMATRIX* WINAPI D3DXMatrixLookAtRH
  805.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
  806.       CONST D3DXVECTOR3 *pUp );
  807.  
  808. // Build a lookat matrix. (left-handed)
  809. D3DXMATRIX* WINAPI D3DXMatrixLookAtLH
  810.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
  811.       CONST D3DXVECTOR3 *pUp );
  812.  
  813. // Build a perspective projection matrix. (right-handed)
  814. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveRH
  815.     ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  816.  
  817. // Build a perspective projection matrix. (left-handed)
  818. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveLH
  819.     ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  820.  
  821. // Build a perspective projection matrix. (right-handed)
  822. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovRH
  823.     ( D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf );
  824.  
  825. // Build a perspective projection matrix. (left-handed)
  826. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovLH
  827.     ( D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf );
  828.  
  829. // Build a perspective projection matrix. (right-handed)
  830. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterRH
  831.     ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  832.       FLOAT zf );
  833.  
  834. // Build a perspective projection matrix. (left-handed)
  835. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterLH
  836.     ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  837.       FLOAT zf );
  838.  
  839. // Build an ortho projection matrix. (right-handed)
  840. D3DXMATRIX* WINAPI D3DXMatrixOrthoRH
  841.     ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  842.  
  843. // Build an ortho projection matrix. (left-handed)
  844. D3DXMATRIX* WINAPI D3DXMatrixOrthoLH
  845.     ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  846.  
  847. // Build an ortho projection matrix. (right-handed)
  848. D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterRH
  849.     ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  850.       FLOAT zf );
  851.  
  852. // Build an ortho projection matrix. (left-handed)
  853. D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterLH
  854.     ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  855.       FLOAT zf );
  856.  
  857. // Build a matrix which flattens geometry into a plane, as if casting
  858. // a shadow from a light.
  859. D3DXMATRIX* WINAPI D3DXMatrixShadow
  860.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR4 *pLight,
  861.       CONST D3DXPLANE *pPlane );
  862.  
  863. // Build a matrix which reflects the coordinate system about a plane
  864. D3DXMATRIX* WINAPI D3DXMatrixReflect
  865.     ( D3DXMATRIX *pOut, CONST D3DXPLANE *pPlane );
  866.  
  867. #ifdef __cplusplus
  868. }
  869. #endif
  870.  
  871.  
  872. //--------------------------
  873. // Quaternion
  874. //--------------------------
  875.  
  876. // inline
  877.  
  878. FLOAT D3DXQuaternionLength
  879.     ( CONST D3DXQUATERNION *pQ );
  880.  
  881. // Length squared, or "norm"
  882. FLOAT D3DXQuaternionLengthSq
  883.     ( CONST D3DXQUATERNION *pQ );
  884.  
  885. FLOAT D3DXQuaternionDot
  886.     ( CONST D3DXQUATERNION *pQ1, CONST D3DXQUATERNION *pQ2 );
  887.  
  888. // (0, 0, 0, 1)
  889. D3DXQUATERNION* D3DXQuaternionIdentity
  890.     ( D3DXQUATERNION *pOut );
  891.  
  892. BOOL D3DXQuaternionIsIdentity
  893.     ( CONST D3DXQUATERNION *pQ );
  894.  
  895. // (-x, -y, -z, w)
  896. D3DXQUATERNION* D3DXQuaternionConjugate
  897.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  898.  
  899.  
  900. // non-inline
  901. #ifdef __cplusplus
  902. extern "C" {
  903. #endif
  904.  
  905. // Compute a quaternin's axis and angle of rotation. Expects unit quaternions.
  906. void WINAPI D3DXQuaternionToAxisAngle
  907.     ( CONST D3DXQUATERNION *pQ, D3DXVECTOR3 *pAxis, FLOAT *pAngle );
  908.  
  909. // Build a quaternion from a rotation matrix.
  910. D3DXQUATERNION* WINAPI D3DXQuaternionRotationMatrix
  911.     ( D3DXQUATERNION *pOut, CONST D3DXMATRIX *pM);
  912.  
  913. // Rotation about arbitrary axis.
  914. D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis
  915.     ( D3DXQUATERNION *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
  916.  
  917. // Yaw around the Y axis, a pitch around the X axis,
  918. // and a roll around the Z axis.
  919. D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll
  920.     ( D3DXQUATERNION *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
  921.  
  922. // Quaternion multiplication.  The result represents the rotation Q2
  923. // followed by the rotation Q1.  (Out = Q2 * Q1)
  924. D3DXQUATERNION* WINAPI D3DXQuaternionMultiply
  925.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  926.       CONST D3DXQUATERNION *pQ2 );
  927.  
  928. D3DXQUATERNION* WINAPI D3DXQuaternionNormalize
  929.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  930.  
  931. // Conjugate and re-norm
  932. D3DXQUATERNION* WINAPI D3DXQuaternionInverse
  933.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  934.  
  935. // Expects unit quaternions.
  936. // if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v)
  937. D3DXQUATERNION* WINAPI D3DXQuaternionLn
  938.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  939.  
  940. // Expects pure quaternions. (w == 0)  w is ignored in calculation.
  941. // if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v)
  942. D3DXQUATERNION* WINAPI D3DXQuaternionExp
  943.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  944.       
  945. // Spherical linear interpolation between Q1 (t == 0) and Q2 (t == 1).
  946. // Expects unit quaternions.
  947. D3DXQUATERNION* WINAPI D3DXQuaternionSlerp
  948.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  949.       CONST D3DXQUATERNION *pQ2, FLOAT t );
  950.  
  951. // Spherical quadrangle interpolation.
  952. // Slerp(Slerp(Q1, C, t), Slerp(A, B, t), 2t(1-t))
  953. D3DXQUATERNION* WINAPI D3DXQuaternionSquad
  954.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  955.       CONST D3DXQUATERNION *pA, CONST D3DXQUATERNION *pB,
  956.       CONST D3DXQUATERNION *pC, FLOAT t );
  957.  
  958. // Setup control points for spherical quadrangle interpolation
  959. // from Q1 to Q2.  The control points are chosen in such a way 
  960. // to ensure the continuity of tangents with adjacent segments.
  961. void WINAPI D3DXQuaternionSquadSetup
  962.     ( D3DXQUATERNION *pAOut, D3DXQUATERNION *pBOut, D3DXQUATERNION *pCOut,
  963.       CONST D3DXQUATERNION *pQ0, CONST D3DXQUATERNION *pQ1, 
  964.       CONST D3DXQUATERNION *pQ2, CONST D3DXQUATERNION *pQ3 );
  965.  
  966. // Barycentric interpolation.
  967. // Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g))
  968. D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric
  969.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  970.       CONST D3DXQUATERNION *pQ2, CONST D3DXQUATERNION *pQ3,
  971.       FLOAT f, FLOAT g );
  972.  
  973. #ifdef __cplusplus
  974. }
  975. #endif
  976.  
  977.  
  978. //--------------------------
  979. // Plane
  980. //--------------------------
  981.  
  982. // inline
  983.  
  984. // ax + by + cz + dw
  985. FLOAT D3DXPlaneDot
  986.     ( CONST D3DXPLANE *pP, CONST D3DXVECTOR4 *pV);
  987.  
  988. // ax + by + cz + d
  989. FLOAT D3DXPlaneDotCoord
  990.     ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV);
  991.  
  992. // ax + by + cz
  993. FLOAT D3DXPlaneDotNormal
  994.     ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV);
  995.  
  996. // non-inline
  997. #ifdef __cplusplus
  998. extern "C" {
  999. #endif
  1000.  
  1001. // Normalize plane (so that |a,b,c| == 1)
  1002. D3DXPLANE* WINAPI D3DXPlaneNormalize
  1003.     ( D3DXPLANE *pOut, CONST D3DXPLANE *pP);
  1004.  
  1005. // Find the intersection between a plane and a line.  If the line is
  1006. // parallel to the plane, NULL is returned.
  1007. D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine
  1008.     ( D3DXVECTOR3 *pOut, CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV1,
  1009.       CONST D3DXVECTOR3 *pV2);
  1010.  
  1011. // Construct a plane from a point and a normal
  1012. D3DXPLANE* WINAPI D3DXPlaneFromPointNormal
  1013.     ( D3DXPLANE *pOut, CONST D3DXVECTOR3 *pPoint, CONST D3DXVECTOR3 *pNormal);
  1014.  
  1015. // Construct a plane from 3 points
  1016. D3DXPLANE* WINAPI D3DXPlaneFromPoints
  1017.     ( D3DXPLANE *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  1018.       CONST D3DXVECTOR3 *pV3);
  1019.  
  1020. // Transform a plane by a matrix.  The vector (a,b,c) must be normal.
  1021. // M should be the inverse transpose of the transformation desired.
  1022. D3DXPLANE* WINAPI D3DXPlaneTransform
  1023.     ( D3DXPLANE *pOut, CONST D3DXPLANE *pP, CONST D3DXMATRIX *pM );
  1024.  
  1025. #ifdef __cplusplus
  1026. }
  1027. #endif
  1028.  
  1029.  
  1030. //--------------------------
  1031. // Color
  1032. //--------------------------
  1033.  
  1034. // inline
  1035.  
  1036. // (1-r, 1-g, 1-b, a)
  1037. D3DXCOLOR* D3DXColorNegative
  1038.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC);
  1039.  
  1040. D3DXCOLOR* D3DXColorAdd
  1041.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  1042.  
  1043. D3DXCOLOR* D3DXColorSubtract
  1044.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  1045.  
  1046. D3DXCOLOR* D3DXColorScale
  1047.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s);
  1048.  
  1049. // (r1*r2, g1*g2, b1*b2, a1*a2)
  1050. D3DXCOLOR* D3DXColorModulate
  1051.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  1052.  
  1053. // Linear interpolation of r,g,b, and a. C1 + s(C2-C1)
  1054. D3DXCOLOR* D3DXColorLerp
  1055.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2, FLOAT s);
  1056.  
  1057. // non-inline
  1058. #ifdef __cplusplus
  1059. extern "C" {
  1060. #endif
  1061.  
  1062. // Interpolate r,g,b between desaturated color and color.
  1063. // DesaturatedColor + s(Color - DesaturatedColor)
  1064. D3DXCOLOR* WINAPI D3DXColorAdjustSaturation
  1065.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s);
  1066.  
  1067. // Interpolate r,g,b between 50% grey and color.  Grey + s(Color - Grey)
  1068. D3DXCOLOR* WINAPI D3DXColorAdjustContrast
  1069.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT c);
  1070.  
  1071. #ifdef __cplusplus
  1072. }
  1073. #endif
  1074.  
  1075.  
  1076.  
  1077.  
  1078. //--------------------------
  1079. // Misc
  1080. //--------------------------
  1081.  
  1082. #ifdef __cplusplus
  1083. extern "C" {
  1084. #endif
  1085.  
  1086. // Calculate Fresnel term given the cosine of theta (likely obtained by
  1087. // taking the dot of two normals), and the refraction index of the material.
  1088. FLOAT WINAPI D3DXFresnelTerm
  1089.     (FLOAT CosTheta, FLOAT RefractionIndex);     
  1090.  
  1091. #ifdef __cplusplus
  1092. }
  1093. #endif
  1094.  
  1095.  
  1096.  
  1097. //===========================================================================
  1098. //
  1099. //    Matrix Stack
  1100. //
  1101. //===========================================================================
  1102.  
  1103. typedef interface ID3DXMatrixStack ID3DXMatrixStack;
  1104. typedef interface ID3DXMatrixStack *LPD3DXMATRIXSTACK;
  1105.  
  1106. // {E3357330-CC5E-11d2-A434-00A0C90629A8}
  1107. DEFINE_GUID( IID_ID3DXMatrixStack,
  1108. 0xe3357330, 0xcc5e, 0x11d2, 0xa4, 0x34, 0x0, 0xa0, 0xc9, 0x6, 0x29, 0xa8);
  1109.  
  1110.  
  1111. #undef INTERFACE
  1112. #define INTERFACE ID3DXMatrixStack
  1113.  
  1114. DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
  1115. {
  1116.     //
  1117.     // IUnknown methods
  1118.     //
  1119.     STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  1120.     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
  1121.     STDMETHOD_(ULONG,Release)(THIS) PURE;
  1122.  
  1123.     //
  1124.     // ID3DXMatrixStack methods
  1125.     //
  1126.  
  1127.     // Pops the top of the stack, returns the current top
  1128.     // *after* popping the top.
  1129.     STDMETHOD(Pop)(THIS) PURE;
  1130.  
  1131.     // Pushes the stack by one, duplicating the current matrix.
  1132.     STDMETHOD(Push)(THIS) PURE;
  1133.  
  1134.     // Loads identity in the current matrix.
  1135.     STDMETHOD(LoadIdentity)(THIS) PURE;
  1136.  
  1137.     // Loads the given matrix into the current matrix
  1138.     STDMETHOD(LoadMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1139.  
  1140.     // Right-Multiplies the given matrix to the current matrix.
  1141.     // (transformation is about the current world origin)
  1142.     STDMETHOD(MultMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1143.  
  1144.     // Left-Multiplies the given matrix to the current matrix
  1145.     // (transformation is about the local origin of the object)
  1146.     STDMETHOD(MultMatrixLocal)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1147.  
  1148.     // Right multiply the current matrix with the computed rotation
  1149.     // matrix, counterclockwise about the given axis with the given angle.
  1150.     // (rotation is about the current world origin)
  1151.     STDMETHOD(RotateAxis)
  1152.         (THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
  1153.  
  1154.     // Left multiply the current matrix with the computed rotation
  1155.     // matrix, counterclockwise about the given axis with the given angle.
  1156.     // (rotation is about the local origin of the object)
  1157.     STDMETHOD(RotateAxisLocal)
  1158.         (THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
  1159.  
  1160.     // Right multiply the current matrix with the computed rotation
  1161.     // matrix. All angles are counterclockwise. (rotation is about the
  1162.     // current world origin)
  1163.  
  1164.     // The rotation is composed of a yaw around the Y axis, a pitch around
  1165.     // the X axis, and a roll around the Z axis.
  1166.     STDMETHOD(RotateYawPitchRoll)
  1167.         (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
  1168.  
  1169.     // Left multiply the current matrix with the computed rotation
  1170.     // matrix. All angles are counterclockwise. (rotation is about the
  1171.     // local origin of the object)
  1172.  
  1173.     // The rotation is composed of a yaw around the Y axis, a pitch around
  1174.     // the X axis, and a roll around the Z axis.
  1175.     STDMETHOD(RotateYawPitchRollLocal)
  1176.         (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
  1177.  
  1178.     // Right multiply the current matrix with the computed scale
  1179.     // matrix. (transformation is about the current world origin)
  1180.     STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1181.  
  1182.     // Left multiply the current matrix with the computed scale
  1183.     // matrix. (transformation is about the local origin of the object)
  1184.     STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1185.  
  1186.     // Right multiply the current matrix with the computed translation
  1187.     // matrix. (transformation is about the current world origin)
  1188.     STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE;
  1189.  
  1190.     // Left multiply the current matrix with the computed translation
  1191.     // matrix. (transformation is about the local origin of the object)
  1192.     STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1193.  
  1194.     // Obtain the current matrix at the top of the stack
  1195.     STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
  1196. };
  1197.  
  1198. #ifdef __cplusplus
  1199. extern "C" {
  1200. #endif
  1201.  
  1202. HRESULT WINAPI 
  1203.     D3DXCreateMatrixStack( 
  1204.         DWORD               Flags, 
  1205.         LPD3DXMATRIXSTACK*  ppStack);
  1206.  
  1207. #ifdef __cplusplus
  1208. }
  1209. #endif
  1210.  
  1211. #include "d3dx8math.inl"
  1212.  
  1213. #pragma warning(default:4201)
  1214.  
  1215. #endif // __D3DX8MATH_H__
  1216.